package com.example.zydraw.view;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.zydraw.draw.IDrawPolicy;

import java.util.ArrayList;
import java.util.List;

public class DiyDrawView extends View {
    public DiyDrawView(Context context) {
        super(context);
    }

    public DiyDrawView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DiyDrawView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DiyDrawView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        for (IDrawPolicy iDrawPolicy : drawPolicyList) {
            iDrawPolicy.draw(canvas);
        }
    }


    private List<IDrawPolicy> drawPolicyList = new ArrayList<>();

    public void setDrawPolicy(IDrawPolicy drawPolicy) {
        drawPolicyList.add(drawPolicy);
    }
}
